package views.activity;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.DefaultCaret;

public class SearchActivityView extends JPanel {
	
	public JLabel lblSearchForAnActivity;
	public JLabel lblProgram;
	
	public JRadioButton rdbtnCurriculumbasedActivity;
	public JRadioButton rdbtnVolunteerbasedActivity;
	public JButton btnReturnToMain;
	public JButton btnNewSearch;
	public JButton btnAddActivity;
	public SearchCurriculumActivityView searchCurriculumActivityView;
	public SearchVolunteerActivityView searchVolunteerActivityView;
	public DefaultTableModel tblModelResults;
	public JTable tblResults;
	
	public JButton btnUpdate;
	public JButton btnClose;
	public JEditorPane edpView;
	
	private JScrollPane scpResults;
	private JScrollPane scpView;
	
	public SearchActivityView() {
		this.setSize(750, 460);
		this.setLayout(null);
		
		lblSearchForAnActivity = new JLabel("Search for an activity:");
		lblSearchForAnActivity.setFont(new Font("Arial Black", Font.PLAIN, 25));
		lblSearchForAnActivity.setBounds(10, 10, 520, 30);
		this.add(lblSearchForAnActivity);
		
		btnReturnToMain = new JButton("Return to Main");
		btnReturnToMain.setFont(new Font("Arial", Font.PLAIN, 12));
		btnReturnToMain.setBounds(360, 10, 120, 25);
		this.add(btnReturnToMain);
		
		btnNewSearch = new JButton("New Search");
		btnNewSearch.setFont(new Font("Arial", Font.PLAIN, 12));
		btnNewSearch.setBounds(620, 10, 120, 25);
		add(btnNewSearch);
		
		btnAddActivity = new JButton("Add Activity");
		btnAddActivity.setFont(new Font("Arial", Font.PLAIN, 12));
		btnAddActivity.setBounds(490, 10, 120, 25);
		add(btnAddActivity);
		
		lblProgram = new JLabel("Program");
		lblProgram.setFont(new Font("Arial", Font.PLAIN, 12));
		lblProgram.setBounds(40, 40, 60, 20);
		this.add(lblProgram);
		
		rdbtnVolunteerbasedActivity = new JRadioButton("Volunteer-Based Activity");
		rdbtnVolunteerbasedActivity.setFont(new Font("Arial", Font.PLAIN, 12));
		rdbtnVolunteerbasedActivity.setBounds(120, 40, 180, 23);
		rdbtnVolunteerbasedActivity.setSelected(true);
		this.add(rdbtnVolunteerbasedActivity);
		
		rdbtnCurriculumbasedActivity = new JRadioButton("Curriculum-Based Activity");
		rdbtnCurriculumbasedActivity.setFont(new Font("Arial", Font.PLAIN, 12));
		rdbtnCurriculumbasedActivity.setBounds(300, 40, 180, 23);
		rdbtnCurriculumbasedActivity.setSelected(false);
		this.add(rdbtnCurriculumbasedActivity);
		
		scpResults = new JScrollPane();
		scpResults.setBounds(10, 70, 730, 379);
		scpResults.setPreferredSize(new Dimension(730, 379));
		scpResults.setVisible(true);
		this.add(scpResults);
		
		tblResults = new JTable() {
			public boolean isCellEditable(int row, int col) {
				return false;
			}
		};
		
		scpView = new JScrollPane();
		scpView.setBounds(440, 70, 300, 349);
		scpView.setVisible(false);
		this.add(scpView);
		
		edpView = new JEditorPane("text/html", "");
		edpView.setFont(new Font("Arial", Font.PLAIN, 12));
		edpView.setEditable(false);
		scpView.setViewportView(edpView);
		
		btnUpdate = new JButton("Update");
		btnUpdate.setBounds(483, 424, 85, 25);
		add(btnUpdate);
		btnUpdate.setFont(new Font("Arial", Font.PLAIN, 12));
		
		btnClose = new JButton("Close");
		btnClose.setBounds(610, 424, 85, 25);
		add(btnClose);
		btnClose.setFont(new Font("Arial", Font.PLAIN, 12));
		btnClose.setVisible(false);
		btnUpdate.setVisible(false);
		
		DefaultCaret caretData = (DefaultCaret)edpView.getCaret();
		caretData.setUpdatePolicy( DefaultCaret.NEVER_UPDATE );
		
		searchCurriculumActivityView = new SearchCurriculumActivityView();
		searchVolunteerActivityView = new SearchVolunteerActivityView();
	}
	
	public void displayResults() {
		scpResults.setViewportView(tblResults);
	}
	
	public void displayCurriculumActivitySearch() {
		scpResults.setViewportView(searchCurriculumActivityView);
	}
	
	public void displayVolunteerActivitySearch() {
		scpResults.setViewportView(searchVolunteerActivityView);
	}
	
	public void openView() {
		scpResults.setSize(new Dimension(420, 379));
		scpView.setVisible(true);
		btnUpdate.setVisible(true);
		btnClose.setVisible(true);
	}
	
	public void closeView() {
		scpResults.setSize(new Dimension(730, 379));
		scpView.setVisible(false);
		btnUpdate.setVisible(false);
		btnClose.setVisible(false);
	}
}
